﻿<UserControl 
    x:Class="AbsyntaxExcelAddIn.Core.ConfigurationDialogueContent"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AbsyntaxExcelAddIn.Core"
    xmlns:cv="clr-namespace:AbsyntaxExcelAddIn.Core.Converters"
    xmlns:res="clr-namespace:AbsyntaxExcelAddIn.Resources;assembly=AbsyntaxExcelAddIn.Resources"
    xmlns:wex="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
    xmlns:ab="clr-namespace:AbsyntaxExcelAddIn.Core.AttachedBehaviours"
    xmlns:bs="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
    xmlns:prims="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit.Extended"
    SnapsToDevicePixels="True"
    UseLayoutRounding="True"
    FocusManager.IsFocusScope="True">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/ExpressionDark.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <SolidColorBrush x:Key="DisabledRuleBackgroundBrush" Color="#FF6D393D" />

            <LinearGradientBrush x:Key="SelectedDisabledRuleBackgroundBrush" EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#FFFDDFDF" Offset="0" />
                <GradientStop Color="#FF734044" Offset="1" />
            </LinearGradientBrush>

            <Style x:Key="SmallIconImageStyle" TargetType="{x:Type Image}">
                <Setter Property="Height" Value="16" />
            </Style>

            <Image x:Key="AddImage" Source="Images/Add.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <Image x:Key="EllipsisImage" Source="Images/Ellipsis.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <Image x:Key="TickImage" Source="Images/Tick.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <Image x:Key="WarningImage" Source="Images/Warning.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <local:AutoGreyableImage x:Key="DeleteImage" Source="Images/Delete.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <local:AutoGreyableImage x:Key="DownArrowImage" Source="Images/DownArrow.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>
            <local:AutoGreyableImage x:Key="UpArrowImage" Source="Images/UpArrow.png" Style="{StaticResource SmallIconImageStyle}" x:Shared="False"/>

            <DataTemplate x:Key="DefaultWatermarkTemplate">
                <ContentControl Foreground="#FF808080" Focusable="False" Content="{Binding}" />
            </DataTemplate>

            <cv:RangeOrderingConverter x:Key="RangeOrderingConverter" />
            <cv:TimeUnitConverter x:Key="TimeUnitConverter" />
            <cv:NullToBoolConverter x:Key="NullToBoolConverter" />
            <cv:ExecutionModeConverter x:Key="ExecutionModeConverter" />
            <cv:BoolToImageConverter x:Key="IsValidToImageConverter" TrueValue="{StaticResource TickImage}" FalseValue="{StaticResource WarningImage}" x:Shared="False" />
            <cv:ExecutionResultToPngUriConverter x:Key="ExecutionResultToPngUriConverter" />
        
            <Style TargetType="{x:Type bs:WatermarkTextBox}" BasedOn="{StaticResource {x:Type TextBox}}" />

            <Style x:Key="GridViewColumnHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Left" />
            </Style>

            <Style TargetType="{x:Type local:AltGroupBox}" BasedOn="{StaticResource {x:Type GroupBox}}">
                <Setter Property="Margin" Value="3" />
                <Setter Property="Padding" Value="3,6,3,2" />
                <Setter Property="BorderThickness" Value="0,1,0,0" />
            </Style>
        
            <Style x:Key="HeaderCheckBox" TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
                <Setter Property="Margin" Value="0,-3" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>

            <Style x:Key="RuleBorderStyle" TargetType="Border">
                <Setter Property="Background" Value="Honeydew" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding Enabled}" Value="False">
                        <DataTrigger.EnterActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Duration="00:00:00.4" To="LavenderBlush" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Duration="00:00:00.4" To="Honeydew" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>

            <SolidColorBrush x:Key="SpinButtonGlyphNormalForegroundFillKey" Color="#FF000000" />

            <DataTemplate x:Key="IncreaseGlyph">
                <Path 
                    Width="7" 
                    Height="4" 
                    VerticalAlignment="Stretch" 
                    Fill="{DynamicResource GlyphBrush}" 
                    Stretch="Fill" 
                    Stroke="{DynamicResource GlyphBrush}" 
                    StrokeThickness="1" 
                    Data="M5.2422477,11.132184 L11.5544,11.132184 8.6412958,4.4969033 z" />
            </DataTemplate>
        
            <DataTemplate x:Key="DecreaseGlyph">
                <Path 
                    Width="7" 
                    Height="4" 
                    VerticalAlignment="Stretch" 
                    Fill="{DynamicResource GlyphBrush}" 
                    Stretch="Fill" 
                    Stroke="{DynamicResource GlyphBrush}" 
                    StrokeThickness="1" 
                    Data="M5.2422477,11.132184 L11.5544,11.132184 8.6412958,4.4969033 z" 
                    RenderTransformOrigin="0.5,0.5">
                    <Path.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="1" />
                            <SkewTransform AngleX="0" AngleY="0" />
                            <RotateTransform Angle="180" />
                            <TranslateTransform X="0" Y="0" />
                        </TransformGroup>
                    </Path.RenderTransform>
                </Path>
            </DataTemplate>

            <Style TargetType="{x:Type bs:ButtonSpinner}">
                <Setter Property="UIElement.Focusable" Value="False" />
                <Setter Property="Control.IsTabStop" Value="True" />
                <Setter Property="Control.HorizontalContentAlignment" Value="Center" />
                <Setter Property="Control.VerticalContentAlignment" Value="Center" />
                <Setter Property="Control.Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type bs:ButtonSpinner}">
                            <Grid>
                                <Border Name="ElementContainer" Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Padding="{TemplateBinding Control.Padding}">
                                    <DockPanel Focusable="False">
                                        <Grid DockPanel.Dock="Right">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="*" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <RepeatButton Name="IncreaseButton" SnapsToDevicePixels="True" Grid.Row="0" ClickMode="Press" IsTabStop="{Binding IsTabStop, RelativeSource={RelativeSource TemplatedParent}}">
                                                <RepeatButton.Template>
                                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                        <ContentPresenter />
                                                    </ControlTemplate>
                                                </RepeatButton.Template>
                                                <Grid Background="Transparent">
                                                    <ContentControl ContentTemplate="{StaticResource IncreaseGlyph}" Margin="5,0" Focusable="False" />
                                                </Grid>
                                            </RepeatButton>
                                            <RepeatButton Name="DecreaseButton" SnapsToDevicePixels="True" Grid.Row="1" ClickMode="Press" IsTabStop="{Binding IsTabStop, RelativeSource={RelativeSource TemplatedParent}}">
                                                <RepeatButton.Template>
                                                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                                                        <ContentPresenter />
                                                    </ControlTemplate>
                                                </RepeatButton.Template>
                                                <Grid Background="Transparent">
                                                    <ContentControl ContentTemplate="{StaticResource DecreaseGlyph}" Margin="5,0" Focusable="False" />
                                                </Grid>
                                            </RepeatButton>
                                        </Grid>
                                        <ContentControl Name="presentationSite" Focusable="False" HorizontalContentAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding Control.VerticalContentAlignment}" Content="{TemplateBinding bs:ButtonSpinner.Content}" />
                                    </DockPanel>
                                </Border>
                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

            <Style x:Key="ListItemContainerStyle" TargetType="{x:Type ListBoxItem}">
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Top" />
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                <Setter Property="ab:ListBoxItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                            <Border
                                Tag="{Binding}"
                                GotFocus="Border_GotFocus"
                                LostFocus="Border_LostFocus"
                                MouseUp="Border_MouseUp"
                                BorderThickness="0,0,0,1"
                                BorderBrush="DarkGray"
                                Padding="10">
                            
                                <Border.Style>
                                    <Style TargetType="{x:Type Border}">
                                        <Setter Property="Background" Value="{StaticResource NormalBrush}" />
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding IsSelected}" Value="True">
                                                <Setter Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Enabled}" Value="False">
                                                <Setter Property="Background" Value="{StaticResource DisabledRuleBackgroundBrush}"/>
                                            </DataTrigger>
                                            <MultiDataTrigger>
                                                <MultiDataTrigger.Conditions>
                                                    <Condition Binding="{Binding IsSelected}" Value="True" />
                                                    <Condition Binding="{Binding Enabled}" Value="False" />
                                                </MultiDataTrigger.Conditions>
                                                <Setter Property="Background" Value="{StaticResource SelectedDisabledRuleBackgroundBrush}"/>
                                            </MultiDataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Border.Style>

                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="*" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" MinWidth="250" />
                                        <ColumnDefinition Width="160" />
                                        <ColumnDefinition Width="70" />
                                        <ColumnDefinition Width="70" />
                                        <ColumnDefinition Width="70" />
                                    </Grid.ColumnDefinitions>
                                
                                    <local:AltGroupBox>
                                        <local:AltGroupBox.Header>
                                            <CheckBox 
                                                Style="{StaticResource HeaderCheckBox}" 
                                                IsChecked="{Binding UsesInput}" 
                                                Content="{x:Static res:TextResources.Input}" />
                                        </local:AltGroupBox.Header>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="4*" />
                                                <ColumnDefinition Width="3*" />
                                                <ColumnDefinition Width="80" />
                                            </Grid.ColumnDefinitions>
                                            <ComboBox 
                                                Margin="0,2,2,2"
                                                ItemsSource="{Binding AvailableSheetNames}" 
                                                SelectedItem ="{Binding InputSheetName}" />
                                            <ComboBox 
                                                x:Name="IRCB"
                                                Grid.Column="1" 
                                                Margin="2" 
                                                IsEditable="True"
                                                ItemsSource="{Binding InputSheetRangeNames, Mode=OneTime}"
                                                Text="{Binding InputCellRange, UpdateSourceTrigger=PropertyChanged}"
                                                MouseUp="CellRangeCombo_MouseUp"
                                                ab:EditableComboBoxBehaviour.MaxLength="255"
                                                ab:EditableComboBoxBehaviour.CharacterCasing="Upper" />
                                            <ComboBox 
                                                Grid.Column="2" 
                                                Margin="2,2,0,2"
                                                ItemsSource="{Binding AvailableRangeOrderingNames, Mode=OneTime}" 
                                                SelectedItem="{Binding InputRangeOrder, Converter={StaticResource RangeOrderingConverter}}" />
                                        </Grid>
                                    </local:AltGroupBox>

                                    <local:AltGroupBox Grid.Column="1" Header="{x:Static res:TextResources.TimeLimit}">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="60" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>
                                            <wex:IntegerUpDown
                                                x:Name="TL"
                                                Height="{Binding ElementName=IRCB, Path=ActualHeight}"
                                                Value="{Binding TimeLimit}"
                                                Minimum="1"
                                                Maximum="999">
                                                <wex:IntegerUpDown.Style>
                                                    <Style TargetType="{x:Type wex:IntegerUpDown}">
                                                        <Setter Property="Control.Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
                                                        <Setter Property="UIElement.Focusable" Value="False" />
                                                        <Setter Property="Control.HorizontalContentAlignment" Value="Right" />
                                                        <Setter Property="Control.VerticalContentAlignment" Value="Center" />
                                                        <Setter Property="Control.Template">
                                                            <Setter.Value>
                                                                <ControlTemplate TargetType="{x:Type Control}">
                                                                    <bs:ButtonSpinner 
                                                                        x:Name="Spinner" 
                                                                        BorderThickness="0" 
                                                                        IsTabStop="False" 
                                                                        AllowSpin="{Binding AllowSpin, RelativeSource={RelativeSource TemplatedParent}}" 
                                                                        ShowButtonSpinner="{Binding ShowButtonSpinner, RelativeSource={RelativeSource TemplatedParent}}">
                                                                        
                                                                        <bs:WatermarkTextBox 
                                                                            x:Name="TextBox" 
                                                                            Padding="0"
                                                                            BorderThickness="1" 
                                                                            MaxLength="3"
                                                                            ContextMenu="{TemplateBinding FrameworkElement.ContextMenu}" 
                                                                            FontFamily="{TemplateBinding Control.FontFamily}" 
                                                                            FontSize="{TemplateBinding Control.FontSize}" 
                                                                            FontStretch="{TemplateBinding Control.FontStretch}" 
                                                                            FontStyle="{TemplateBinding Control.FontStyle}" 
                                                                            FontWeight="{TemplateBinding Control.FontWeight}" 
                                                                            HorizontalContentAlignment="{TemplateBinding Control.HorizontalContentAlignment}" 
                                                                            MinWidth="20" 
                                                                            AcceptsReturn="False" 
                                                                            TextWrapping="NoWrap" 
                                                                            VerticalContentAlignment="{TemplateBinding Control.VerticalContentAlignment}" 
                                                                            SelectAllOnGotFocus="{Binding SelectAllOnGotFocus, RelativeSource={RelativeSource TemplatedParent}}" 
                                                                            TextAlignment="{Binding TextAlignment, RelativeSource={RelativeSource TemplatedParent}}" 
                                                                            Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" 
                                                                            Watermark="{Binding Watermark, RelativeSource={RelativeSource TemplatedParent}}" 
                                                                            WatermarkTemplate="{Binding WatermarkTemplate, RelativeSource={RelativeSource TemplatedParent}}">
                                                                            <bs:WatermarkTextBox.Style>
                                                                                <Style TargetType="{x:Type bs:WatermarkTextBox}" BasedOn="{StaticResource {x:Type TextBox}}" />
                                                                            </bs:WatermarkTextBox.Style>
                                                                        </bs:WatermarkTextBox>
                                                                    </bs:ButtonSpinner>
                                                                </ControlTemplate>
                                                            </Setter.Value>
                                                        </Setter>
                                                        <Setter Property="prims:InputBase.TextAlignment" Value="Right" />
                                                        <Setter Property="prims:InputBase.WatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
                                                    </Style>
                                                </wex:IntegerUpDown.Style>
                                            </wex:IntegerUpDown>
                                            <ComboBox 
                                                Grid.Column="1" 
                                                Margin="2,2,0,2"
                                                ItemsSource="{Binding AvailableTimeUnits, Mode=OneTime}"
                                                SelectedItem="{Binding Unit, Converter={StaticResource TimeUnitConverter}}" />
                                        </Grid>
                                    </local:AltGroupBox>

                                    <local:AltGroupBox Grid.Column="2" Header="{x:Static res:TextResources.Reload}">
                                        <CheckBox 
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"
                                            IsChecked="{Binding ReloadProjectBeforeExecuting}" />
                                    </local:AltGroupBox>

                                    <local:AltGroupBox 
                                        Grid.Column="3" 
                                        Header="{x:Static res:TextResources.Enabled}">

                                        <CheckBox 
                                            VerticalAlignment="Center"
                                            HorizontalAlignment="Center"
                                            IsChecked="{Binding Enabled}" />
                                    </local:AltGroupBox>

                                    <local:AltGroupBox 
                                        Grid.Column="4" 
                                        Header="{x:Static res:TextResources.Status}" 
                                        Content="{Binding IsValid, Converter={StaticResource IsValidToImageConverter}}" />

                                    <local:AltGroupBox Grid.Row="1">
                                        <local:AltGroupBox.Header>
                                            <CheckBox 
                                                Style="{StaticResource HeaderCheckBox}"
                                                IsChecked="{Binding UsesOutput}" 
                                                Content="{x:Static res:TextResources.Output}" />
                                        </local:AltGroupBox.Header>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="4*" />
                                                <ColumnDefinition Width="3*" />
                                                <ColumnDefinition Width="80" />
                                            </Grid.ColumnDefinitions>
                                            <ComboBox 
                                                Margin="0,2,2,2"
                                                ItemsSource="{Binding AvailableSheetNames}" 
                                                SelectedItem ="{Binding OutputSheetName}" />
                                            <ComboBox 
                                                Grid.Column="1" 
                                                Margin="2" 
                                                IsEditable="True"
                                                ItemsSource="{Binding OutputSheetRangeNames, Mode=OneTime}"
                                                Text="{Binding OutputCellRange, UpdateSourceTrigger=PropertyChanged}"
                                                MouseUp="CellRangeCombo_MouseUp"
                                                ab:EditableComboBoxBehaviour.MaxLength="255"
                                                ab:EditableComboBoxBehaviour.CharacterCasing="Upper" />
                                            <ComboBox 
                                                Grid.Column="2" 
                                                Margin="2,2,0,2"
                                                ItemsSource="{Binding AvailableRangeOrderingNames, Mode=OneTime}" 
                                                SelectedItem="{Binding OutputRangeOrder, Converter={StaticResource RangeOrderingConverter}}" />
                                        </Grid>
                                    </local:AltGroupBox>

                                    <local:AltGroupBox Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Header="{x:Static res:TextResources.Project}">
                                        <DockPanel LastChildFill="True">
                                            <Button 
                                                DockPanel.Dock="Right" 
                                                Tag="{Binding}" 
                                                Click="BrowseProjectsButton_Click" 
                                                Width="18"
                                                Height="18"
                                                Padding="2"
                                                Content="{StaticResource EllipsisImage}" />
                                            <TextBox 
                                                x:Name="PP" 
                                                Height="{Binding ElementName=IRCB, Path=ActualHeight}"
                                                Margin="0,0,2,0"
                                                MaxLength="260"
                                                Text="{Binding ProjectPath, UpdateSourceTrigger=PropertyChanged}" />
                                        </DockPanel>
                                    </local:AltGroupBox>

                                    <local:AltGroupBox 
                                        Grid.Row="1" 
                                        Grid.Column="4" 
                                        Header="{x:Static res:TextResources.LastRun}">
                                        <Image 
                                            Style="{StaticResource SmallIconImageStyle}" 
                                            Source="{Binding LastExecutionResult, Converter={StaticResource ExecutionResultToPngUriConverter}}" />
                                    </local:AltGroupBox>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
        
    </UserControl.Resources>

    <Border BorderThickness="0" Background="{StaticResource ControlBackgroundBrush}">
        <Grid Margin="10,2,10,10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <ToolBar KeyboardNavigation.TabNavigation="Continue">
                <ToolBar.Resources>
                    <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
                        <Setter Property="Height" Value="25" />
                        <Setter Property="MinWidth" Value="40"/>
                        <Setter Property="Margin" Value="2,0"/>
                    </Style>
                </ToolBar.Resources>
                <Button 
                    Content="{StaticResource AddImage}" 
                    ToolTip="{x:Static res:TextResources.ToolTip_AddRule}"
                    Click="AddRuleButton_Click" />
                <Button 
                    Content="{StaticResource DeleteImage}" 
                    ToolTip="{x:Static res:TextResources.ToolTip_RemoveRule}"
                    IsEnabled="{Binding SelectedRule, Converter={StaticResource NullToBoolConverter}}"
                    Click="RemoveRuleButton_Click" />
                <Button 
                    Content="{StaticResource DownArrowImage}" 
                    ToolTip="{x:Static res:TextResources.ToolTip_Demote}"
                    IsEnabled="{Binding CanDemoteSelectedRule}"
                    Click="DemoteRuleButton_Click" />
                <Button 
                    Content="{StaticResource UpArrowImage}" 
                    ToolTip="{x:Static res:TextResources.ToolTip_Promote}"
                    IsEnabled="{Binding CanPromoteSelectedRule}"
                    Click="PromoteRuleButton_Click" />
                <Separator />
                <ComboBox 
                    Margin="3"
                    ToolTip="{x:Static res:TextResources.ToolTip_Mode}"
                    ItemsSource="{Binding AvailableExecutionModeNames, Mode=OneTime}" 
                    SelectedItem="{Binding Mode, Converter={StaticResource ExecutionModeConverter}}" 
                    VerticalAlignment="Stretch" />
            </ToolBar>

            <ListBox 
                Grid.Row="1"
                ItemsSource="{Binding Rules}" 
                ItemContainerStyle="{StaticResource ListItemContainerStyle}"
                ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                SelectedItem="{Binding SelectedRule}"
                KeyboardNavigation.TabNavigation="Continue" 
                SelectionMode="Single"
                VirtualizingStackPanel.IsVirtualizing="False"
                FocusManager.IsFocusScope="True" />
            
            <StackPanel 
                Grid.Row="2" 
                Orientation="Horizontal"
                HorizontalAlignment="Right">
            
                <StackPanel.Resources>
                    <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
                        <Setter Property="Margin" Value="10,10,0,0" />
                        <Setter Property="Width" Value="70" />
                        <Setter Property="Height" Value="20" />
                    </Style>
                </StackPanel.Resources>
                <Button Click="OkButton_Click" Content="{x:Static res:TextResources.Caption_Ok}" />
                <Button Click="CancelButton_Click" Content="{x:Static res:TextResources.Caption_Cancel}" IsCancel="True" />
            </StackPanel>
        </Grid>
    </Border>
</UserControl>
